﻿using Ebusiness_ProductService.Services;
using Ebusiness_ProductService.Services.Dtos.Product;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.Application.Dtos;
using Volo.Abp.AspNetCore.Mvc;

namespace Ebusiness_Gateway.Controllers
{
    [Route("Product/[action]")]
    [ApiController]
    public class ProductController : AbpController, IProductService
    {
        public IProductService productService { get; set; }

        public ProductController()
        {

        }

        /// <summary>
        /// 获取列表数据
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<ProductDto>> GetList()
        {
            var dtos = await productService.GetListAsync(new PagedAndSortedResultRequestDto() { MaxResultCount = 50, SkipCount = 0 });
            return dtos.Items.ToList();
        }

        [HttpGet]
        public async Task<ProductDto> GetAsync(Guid id)
        {
            return await productService.GetAsync(id);
        }

        [HttpPost]
        public async Task<PagedResultDto<ProductDto>> GetListAsync(PagedAndSortedResultRequestDto input)
        {
            return await productService.GetListAsync(input);
        }

        [HttpPost]
        public async Task<ProductDto> CreateAsync(ProductDto input)
        {
            return await productService.CreateAsync(input);
        }

        [HttpPut]
        public async Task<ProductDto> UpdateAsync(Guid id, ProductDto input)
        {
            return await productService.UpdateAsync(id, input);
        }

        [HttpDelete]
        public async Task DeleteAsync(Guid id)
        {
            await productService.DeleteAsync(id);
        }
    }
}
